package qc.module.iot.protocol.sl651;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * SL651数据帧功能码枚举，按照附录B 表B.1功能码定义
 *
 * @author QuCheng Tech
 * @since 2025/11/7
 */
@Getter
@AllArgsConstructor
public enum SL651_FrameFunctionCodeEnum {
    UN_DEFINE(0, "保留"),
    HEART_BEAT(0x2F, "链路维持报"),
    REPORT_TEST(0x30, "测试报"),
    REPORT_PERIOD(0x31, "均匀时段水文信息报"),
    REPORT_TIMER(0x32, "遥测站定时报"),
    REPORT_ADD(0x33, "遥测站加报报"),
    REPORT_HOUR(0x34, "遥测站小时报"),
    REPORT_MANUAL(0x35, "遥测站人工置数报"),
    REPORT_PICTURE(0x36, "遥测站图片报");

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值，限制为1字节
     * @return qc.module.iot.protocol.sl651.SL651_FrameFunctionCodeEnum
     * @author QuCheng Tech
     * @since 2025/11/9
     */
    public static SL651_FrameFunctionCodeEnum getSL651FrameFunctionCodeEnum(int index) {
        if (index > 0x0) {
            int byteIntValue = index & 0xFF;//传入的值限制为1字节，最大0xFF
            if (byteIntValue > 0x0) {
                for (SL651_FrameFunctionCodeEnum item : SL651_FrameFunctionCodeEnum.values()) {
                    if (item.getIndex() == byteIntValue) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return SL651_FrameFunctionCodeEnum.UN_DEFINE;
    }
}
